package main

import (
	"fmt"

	"github.com/DATA-DOG/go-sqlmock"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type MockGormV2 struct {
	DB   *gorm.DB
	mock sqlmock.Sqlmock
}

// gorm.io版本的mock
func MockDBGorm_V2() {
	db, mock, err := sqlmock.New()
	if nil != err {
		fmt.Printf("an error '%s' was not expected when opening a stub database connection", err)
		return
	}
	defer db.Close()

	mockDb := &MockGormV2{}
	mockDb.mock = mock

	mockDb.DB, err = gorm.Open(mysql.New(mysql.Config{
		Conn:                      db,
		SkipInitializeWithVersion: true, // 跳过数据库初始化错误
	}), &gorm.Config{})
	if nil != err {
		fmt.Println("fail to mock gormDB: ", err)
		return
	}

}
